<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link rel="stylesheet" href="../../component/layui/css/layui.css" media="all">
    <script src="../../component/jquery3.6.0.js"></script>
    <style>
    .search_month{
      position:absolute;
      left:170px;
      top: 10px;
    }


  </style>
</head>
<body>
    <!-- 内容主体区域 -->
    <div style="margin-top: 20px;margin-left: 15px">销售管理>>销售计划</div>

    <div class="layui-form">
      <div class="layui-form-item">

          <div class="layui-inline search_month">
              <div class="layui-input-inline">
                  <input type="text" class="layui-input" id="search_name" name="search_name" placeholder="请输入计划编码">
              </div>
              <button type="button" class="layui-btn" onclick="reLoad()">查询用户</button>
          </div>

      </div>
    </div>
    <hr>


    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="add_new">添加</button>
        </div>
    </script>

    <table class="layui-hide" id="test" lay-filter="test"></table>

<!-- 文件导入-->
<script type="text/javascript" src="../../component/layui/layui.js"></script>

<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit" >修改</a>
  <a class="layui-btn layui-btn-xs" lay-event="sub" >提交</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" >删除</a>
</script>

    <script>
        var zs_saleplan_code;
        var zs_planner_name;
        var zs_planner_month;
        var zs_status_name;
        var zs_planner_text;
        var zs_saleplan_id;
        var zs_emp_name;
        var zs_planner_month;

        var table_re;
        function reLoad(){
            var search_name=$('#search_name').val();
            console.log(search_name);
            table_re.reload({
                url:'http://localhost:8181/Manager_war/SpServlet/list_search?search_name='+search_name
            })
        }
        layui.use('table', function(){
            var table = layui.table;

            //ajax->getJson去请求后端




            table_re=table.render({
                elem: '#test'
                ,url:'http://localhost:8181/Manager_war/SpServlet/list'
                ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                    title: '提示'
                    ,layEvent: 'LAYTABLE_TIPS'
                    ,icon: 'layui-icon-tips'
                }]
                ,title: '用户数据表'
                ,cols: [[
                    {type: 'checkbox', fixed: 'left'}
                    ,{field:'saleplan_id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
                    ,{field:'emp_name', title:'姓名', width:120}
                    ,{field:'planner_month', title:'月份', width:150}
                    ,{field:'status_name', title:'状态', width:100}
                    ,{field:'last_time', title:'最后登录时间',width: 150}
                    ,{field:'current_name', title:'操作人', width:80}
                    ,{field:'dispose_name', title:'处理人', width:120}
                    ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:250}
                ]]
                ,page: true
            });

            //头工具栏事件
            table.on('toolbar(test)', function(obj){
                var checkStatus = table.checkStatus(obj.config.id);
                switch(obj.event){
                    case 'add_new':
                        layer.open({
                            type:2
                            ,title:'提交'
                            ,area: ['340px','460px']
                            ,shadeClose:false
                            //,btn:['确定','取消']
                            ,content:'plans/add_sp.html'
                        });
                        //var data = checkStatus.data;
                        //layer.alert(JSON.stringify(data));
                        break;

                    //自定义头工具栏右侧图标 - 提示
                    case 'LAYTABLE_TIPS':
                        layer.alert('这是工具栏右侧自定义的一个图标按钮');
                        break;
                };
            });


            //监听行工具事件
            table.on('tool(test)', function(obj){
                var data = obj.data;

                if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(index){
                        obj.del();
                        console.log(data.saleplan_id);
                        $.ajax({
                            url:'http://localhost:8181/Manager_war/SpServlet/del',
                            data:"saleplan_id="+data.saleplan_id,
                            dataType:'json',
                            // contentType:'application/json',form text  请求的格式 给后端是以json格式进行传输
                            type:'post',
                            success:function(result){
                                if(result.code==0){
                                    layer.msg(result.msg,{icon:1,time:1000},function(){
                                        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                                        window.parent.location.reload(true);
                                    });
                                }else{
                                    layer.msg(result.msg,{icon:2,time:1000});
                                }
                            }
                        });
                        layer.close(index);
                    });
                }

                else if(obj.event==='detail'){

                    zs_saleplan_code=data.saleplan_code;
                    zs_planner_name=data.planner_name;
                    zs_planner_month=data.planner_month;
                    zs_status_name=data.status_name;
                    zs_planner_text=data.planner_text;
                    layer.open({
                        type:2
                        ,title:'查看销售计划信息'
                        ,area: ['340px', '470px']
                        ,shadeClose:false
                        ,content: "plans/detail_sp.html"
                    });

                }

                else if(obj.event === 'edit'){
                    zs_saleplan_id=data.saleplan_id;
                    zs_saleplan_code=data.saleplan_code;
                    zs_planner_name=data.planner_name;
                    zs_planner_month=data.planner_month;
                    zs_status_name=data.status_name;
                    zs_planner_text=data.planner_text;
                    layer.open({
                        type:2
                        ,title:'修改销售计划信息'
                        ,area: ['340px', '470px']
                        ,shadeClose:false
                        ,content:'plans/modify_sp.html'
                    })

                }


                else if(obj.event==='sub'){
                    //layer.confirm('真的要提交吗');
                    layer.open({
                        type:0
                        ,title:'提交'
                        ,shadeClose:true
                        ,btn:['确定','取消']
                        ,content:'真的要提交信息吗'
                        ,yes:function (index){
                            //alert(data.saleplan_id);
                            obj.update({
                                status_name: '已提交'
                            });
                            $.ajax({
                                url:"http://localhost:8181/Manager_war/SpServlet/subm",
                                data:"saleplan_id="+data.saleplan_id,
                                dataType:'json',
                                // contentType:'application/json',form text  请求的格式 给后端是以json格式进行传输
                                type:'post',
                                success:function(result){
                                    console.log(result);
                                    if(result.code==0){
                                        layer.msg(result.msg,{icon:1,time:1000},function(){
                                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                                            window.parent.location.reload()
                                        });
                                    }else{
                                        console.log(result);
                                        layer.msg(result.msg,{icon:2,time:1000});
                                    }
                                }
                            });
                        }
                    });
                }
            });
        });
    </script>

    <script>
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            //年月选择器
            laydate.render({
                elem: '#test3'
                ,type: 'month'
            });
        });
    </script>
</body>
</html>